package leetcode.easy.q26;

import java.util.Arrays;

//26. 删除有序数组中的重复项
public class Q {
    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3, 3, 4, 5, 5, 5, 6};
        int lengh = new Solution().removeDuplicates(nums);
        System.out.printf(Arrays.toString(Arrays.copyOf(nums, lengh)));
    }
}

class Solution {
    public int removeDuplicates(int[] nums) {
        if (nums == null || nums.length == 0) return 0;
        int next = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[next - 1]) {
                nums[next++] = nums[i];
            }
        }
        return next;
    }
}